package com.serverTechnology.resource.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import com.serverTechnology.resource.entity.ManagementEntity;
import com.serverTechnology.resource.entity.dto.InsertManagementDto;
import com.serverTechnology.resource.entity.dto.ManagementInsertDto;
import com.serverTechnology.resource.entity.dto.ManagementPageDto;
import com.serverTechnology.resource.entity.dto.ManagementUpdateVo;
import com.serverTechnology.resource.entity.vo.InsertFidAndNameVo;
import com.serverTechnology.resource.entity.vo.ManagePageVo;
import com.serverTechnology.resource.entity.vo.ManagementInfoVo;
import com.serverTechnology.resource.entity.vo.MangeParamVo;
import com.serverTechnology.resource.service.IManagementService;
import io.swagger.annotations.*;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 设备、工具、工装管理 接口
 *
 * @author 王烁
 * @since 2024-07-28
 */
@Api(tags = "设备、工具、工装管理")
@RestController
@RequestMapping("/management")
@ApiResource(name = "设备、工具、工装管理的接口")
public class ManagementController {

    @Autowired
    private IManagementService iManagementService;

    /***
     *  添加设备、工具、工装管理
     * @param managementInsertDto
     * @return
     */
    @ApiOperation("添加设备、工具、工装管理")
    @PostMapping("/insertManagement")
    public ResponseData add(@RequestBody @Validated ManagementInsertDto managementInsertDto) {
        iManagementService.add(managementInsertDto);
        return new SuccessResponseData("添加成功");
    }

    /**
     * 查询设备类型
     * @param deviceDistinguish 设备EQUIPMENT，工具TOOL，工装FROCK
     * @return
     */
    @ApiOperation("查询设备类型")
    @ApiModelProperty(value = "")
    @GetMapping("/getManagement")
    public ResponseData<List<InsertFidAndNameVo>> getManagement(@RequestParam(value = "deviceDistinguish") @NotNull(message = "区分不能为空") String deviceDistinguish) {
        List<InsertFidAndNameVo> classifyTypeList = iManagementService.classifyType(deviceDistinguish);
        return new SuccessResponseData(classifyTypeList);
    }

    /**
     * 分页查询设备
     *
     * @param resource
     * @return
     */
    @ApiOperation("分页查询设备")
    @GetMapping("/getManagementPage")
    public ResponseData<PageResult<ManagePageVo>> getManagementPage(ManagementPageDto resource) {
        PageResult<ManagePageVo> managementPage = iManagementService.getManagementPage(resource);
        return new SuccessResponseData(managementPage);
    }

    /***
     * 根据id进行查询详情
     * @param id 管理id
     * @return 详情数据
     */
    @ApiOperation("根据id进行查询详情")
    @GetMapping("/getManagementById")
    public ResponseData<ManagementInfoVo> getManagementById(@RequestParam(value = "id") @NotNull(message = "id不能为空") Long id) {
        ManagementInfoVo managementEntity = iManagementService.getManagementById(id);
        return new SuccessResponseData(managementEntity);
    }

    /***
     * 根据id进行编辑
     * @param managementEntity 管理id
     * @return 删除结果
     */
    @ApiOperation("根据id进行编辑")
    @PostMapping("/updateManagement")
    public ResponseData updateManagement(@RequestBody ManagementUpdateVo managementEntity) {
        iManagementService.updateManagement(managementEntity);
        return new SuccessResponseData();
    }

    /**
     * 根据id删除
     *
     * @param id 管理id
     * @return
     */
    @ApiOperation("根据id删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "设备id", dataType = "Long", paramType = "query", required = true)
    })
    @DeleteMapping("/deleteManagement")
    public ResponseData deleteManagement(@NotNull(message = "参数不能为null") Long id) {
        iManagementService.deleteManagement(id);
        return new SuccessResponseData("删除成功");
    }

    /**
     *  设备配置详情
     * @param deviceId 类型id
     * @param resourceId 设备id
     * @return
     */
    @ApiOperation("设备配置详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "类型 配置参数表 的id", dataType = "Long", paramType = "query", required = true),
            @ApiImplicitParam(name = "resourceId", value = "设备id", dataType = "Long", paramType = "query", required = true)
    })
    @GetMapping("/getManagementDetail")
    public ResponseData<List<MangeParamVo>> getManagementDetail(@NotNull(message = "id不能为空") List<Long> deviceId, List<Long> resourceId) {
        List<MangeParamVo> cagetyVo=  iManagementService.getManagementDetail(deviceId,resourceId);
        return new SuccessResponseData(cagetyVo);
    }

    /**
     *  新增设备配置OPC标签和修改设备配置OPC标签
     * @param insertManagementDto
     * @return
     */
    @ApiOperation("新增设备配置OPC标签和修改设备配置OPC标签")
    @PostMapping("/insertManagementDetail")
    public ResponseData insertManagementDetail(@RequestBody @Validated List<InsertManagementDto> insertManagementDto) {
        iManagementService.insert(insertManagementDto);
        return new SuccessResponseData("添加成功");
    }

    /***
     * 工艺接口
     * 根据设备、工装、工具进行批量查询
     * @param ids
     * @return
     */
    @ApiOperation("根据设备、工装、工具进行批量查询")
    @PostMapping("/craftByIds")
    public ResponseData<ManagementEntity> craftByIds(@RequestBody List<Long> ids) {
        List<ManagementEntity> craftedByIds =   iManagementService.craftByIds(ids);
        return new SuccessResponseData(craftedByIds);
    }


}
